package cn.com.b2office.dao.hibernate;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.b2office.dao.TaggedItemDao;
import cn.com.b2office.domain.TaggedItem;

public class TaggedItemDaoHibernateImpl extends HibernateDaoSupport implements
		TaggedItemDao {

	private static final Log logger = LogFactory
			.getLog(TaggedItemDaoHibernateImpl.class);

	@SuppressWarnings("unchecked")
	public List<TaggedItem> listTaggedItems(String tagId, int firstResult,
			int maxResults) {
		List<TaggedItem> list = null;
		Session s = getSession();
		String hql = "from TaggedItem where tagId=:tagId";
		try {
			list = s.createQuery(hql).setString("tagId", tagId).setFirstResult(
					firstResult).setMaxResults(maxResults).list();
		} catch (HibernateException e) {
			logger.error("throw Exception:" + e.getMessage());
			throw e;
		} finally {
			releaseSession(s);
		}
		return list;
	}

}
